package com.jinzhi.jzweb.controller;


import java.time.LocalDate;
import java.util.*;

import com.jinzhi.jzweb.annotation.OrderLog;
import com.jinzhi.jzweb.domain.vo.JazGroupActivityVo;
import com.jinzhi.jzweb.domain.vo.JazGroupOrderVo;
import com.jinzhi.jzweb.domain.vo.JazGroupProdVo;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazGroupOrderDO;
import com.jinzhi.jzweb.service.JazGroupOrderService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 团购订单表
 * </pre>
 * <small> 2024-05-11 13:54:20 | Long</small>
 */
@RestController
@RequestMapping("/jzweb/jazGroupOrder")
public class JazGroupOrderController extends BaseController {
	@Autowired
	private JazGroupOrderService jazGroupOrderService;

	@ApiOperation(value = "订单列表页面入口", notes = "订单列表页面入口")
	@ApiImplicitParams({
	})
	@ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
			@ApiResponse(code = 500, message = "服务器内部异常")})
	@GetMapping("")
	@RequiresPermissions("jzweb:jazGroupOrder:jazGroupOrder")
	String JazGroupOrder(){
	    return "jzweb/jazGroupOrder/jazGroupOrder";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:jazGroupOrder:jazGroupOrder")
	public Result<Page<JazGroupOrderDO>> list(JazGroupOrderDO jazGroupOrderDTO){
		// 查询列表数据
		Page<JazGroupOrderDO> page = jazGroupOrderService.selectPage(getPage(JazGroupOrderDO.class),
					jazGroupOrderService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				JazGroupOrderDO obj = (JazGroupOrderDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}


	/**
	 *  单独购买订单列表查询
	 * @return
	 */
	@GetMapping("/selGroupOrderList")
	@ResponseBody
	public Result<Page<JazGroupOrderDO>> selGroupOrderList(@RequestParam(value = "name",required = false) String name,
															 @RequestParam(value = "mobile",required = false) String mobile,
															 @RequestParam("current")int current,
															 @RequestParam("size")int size,
															 @RequestParam(value = "createTime",required = false) String createTime,
															 @RequestParam(value = "endTime",required = false)String endTime,
															 @RequestParam(value = "status",required = false)String status
														   )  {

		return jazGroupOrderService.selGroupOrderList(name,mobile,current,size,createTime,endTime,status);
	}

	/**
	 *  拼团订单列表查询
	 * @return
	 */
	@GetMapping("/selActivityOrderList")
	@ResponseBody
	public Result<Page<JazGroupOrderDO>> selActivityOrderList(@RequestParam(value = "name",required = false) String name,
														   @RequestParam(value = "mobile",required = false) String mobile,
														   @RequestParam("current")int current,
														   @RequestParam("size")int size,
														   @RequestParam(value = "createTime",required = false) String createTime,
														   @RequestParam(value = "endTime",required = false)String endTime,
														   @RequestParam(value = "status",required = false)String status
	)  {

		return jazGroupOrderService.selGroupOrderList1(name,mobile,current,size,createTime,endTime,status);
	}

	/**
	 * 拼团详情
	 * @return
	 */
	@GetMapping("/getInfo")
	public Result<?> getInfo(@RequestParam("id")Long id )  {
		JazGroupOrderVo vo=jazGroupOrderService.getInfo(id);
		return Result.ok(vo);

	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazGroupOrder:add")
	String add(){
	    return "jzweb/jazGroupOrder/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazGroupOrder:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazGroupOrderDO jazGroupOrder = jazGroupOrderService.selectById(id);
		model.addAttribute("jazGroupOrder", jazGroupOrder);
	    return "jzweb/jazGroupOrder/edit";
	}
	
	@OrderLog(value = "添加团购订单表",sysModule = 101,operationType =1)
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazGroupOrder:add")
	public Result<String> save( JazGroupOrderDO jazGroupOrder){
		jazGroupOrderService.insert(jazGroupOrder);
        return Result.ok();
	}
	
	@OrderLog(value ="修改团购订单表",sysModule = 101,operationType =3)
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazGroupOrder:edit")
	public Result<String>  update( JazGroupOrderDO jazGroupOrder){
		boolean update = jazGroupOrderService.updateById(jazGroupOrder);
		return update ? Result.ok() : Result.fail();
	}
	
	@OrderLog(value ="删除团购订单表",sysModule = 101,operationType =2)
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazGroupOrder:remove")
	public Result<String>  remove( Long id){
		jazGroupOrderService.deleteById(id);
        return Result.ok();
	}
	
	@OrderLog(value ="批量删除团购订单表",sysModule = 101,operationType =2)
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazGroupOrder:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazGroupOrderService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
